﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using ZBJF.Warranty.BLL;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Common.Enums.InsuranceProducts;
using ZBJF.Warranty.Model.ViewModel.InsuranceProducts;

namespace ZBJF.Warranty.H5.Controllers
{
    public class InsuranceProductOrderCardController : BaseController
    {
        public ActionResult Index()
        {
            return View();
        }

        public JsonResult GetInsuranceProductOrderCardByOneMonth(InsuranceProductOrderCardModel model)
        {
            model.SellerEmployeeID = CurrentUser.ID;
            int total;
            model.iSorts = "CreateTime desc";
            var list = ServiceFactory.InsuranceProductOrderCardServiceInstance.GetPagingList(model, out total).AsNoTracking().ToList().Select(o => new
            {
                InsuranceProductOrderID = o.InsuranceProductOrder.ID,
                InsuranceProductName = o.InsuranceProductName,
                o.CardNo,
                o.CardPassword,
                StatusDesc = EnumHelper.Instance.GetDescription(typeof(InsuranceProductOrderCardStatus), o.Status),
                CreateTime = o.CreateTime.ToString("MM月dd日 HH:mm")
            });
            var dtMonth = model.MonthDateTime.HasValue
                ? model.MonthDateTime.Value.ToString("yyyyMM")
                : DateTime.Now.ToString("yyyyMM");
            var saleIncome = ServiceFactory.InsuranceProductOrderServiceInstance.GetSellerInsuranceProductSaleIncome(dtMonth,CurrentUser.ID);
            var saleCount = ServiceFactory.InsuranceProductOrderCardServiceInstance.GetInsuranceCardSaleCount(dtMonth,CurrentUser.ID);
            return Json(new
            {
                saleIncome,
                saleCount,
                isLastPage = model.iDisplayStart + model.iDisplayLength > total,
                list,
            }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 获取销售收入
        /// </summary>
        /// <param name="dtMonth"></param>
        /// <returns></returns>
        public JsonResult GetInsuranceCardSaleIncome(string dtMonth)
        {
            var saleIncome = ServiceFactory.InsuranceProductOrderServiceInstance.GetSellerInsuranceProductSaleIncome(dtMonth,CurrentUser.ID);
            return Json(new { saleIncome });
        }
        /// <summary>
        /// 获取销售量
        /// </summary>
        /// <param name="dtMonth"></param>
        /// <returns></returns>
        public JsonResult GetInsuranceCardSaleCount(string dtMonth)
        {
            var saleCount = ServiceFactory.InsuranceProductOrderCardServiceInstance.GetInsuranceCardSaleCount(dtMonth,CurrentUser.ID);
            return Json(new { saleCount });
        }
    }
}